package com.gitee.elf.core.entity

import com.gitee.elf.core.entity.event.EntityEventManager
import org.bukkit.entity.EntityType
import taboolib.library.configuration.ConfigurationSection
import taboolib.module.configuration.Configuration
import java.io.File

class EntityTheme(val file: File) {

    val id = file.nameWithoutExtension
    val config = Configuration.loadFromFile(file)

    val option = config.getConfigurationSection("__option__")
    val name = option?.getString("name", id)!!

    val type = option?.getString("type", "wolf")!!

    val entityMapping = EntityManager.getEntityMappingClass(type)

    val events = config.getKeys(false).mapNotNull {
        if (it != "__option__") {
            EventHandler(config.getConfigurationSection(it)!!)
        } else null
    }

    class EventHandler(val config: ConfigurationSection) {

        val id = config.name
        val bind = config.getString("$", config.getString("bind"))!!
        val bindEvent = EntityEventManager.getEvent(bind)
        val action = config.getString("action")!!

        val baffle = config.getLong("baffle")

    }

    override fun toString(): String {
        return "EntityTheme(id='$id', name='$name', type='$type', entityMapping=$entityMapping)"
    }


}